import 'package:cat_eye/base/base_view_model.dart';
import 'package:cat_eye/bean/home_body_bean.dart';
import 'package:cat_eye/config/url_config.dart';
import 'package:flutter/material.dart';

/*
* @Package: view_model.find_view_model
* @ClassName: find_classification_details_view_model
* @Author: szj
* @CreateDate: 8/2/21 5:00 PM
* TODO 首页-分类-分类详情ViewModel
*/
class FindClassificationDetailsViewModel extends BaseViewModel {
  int id;

  //必要参数
  static const DETAILS_NECESSARY_PARAMETERS =
      "&udid=d2807c895f0348a180148c9dfa6f2feeac0781b5&deviceModel=Android";

  String loadMoreUrl = "";

  FindClassificationDetailsViewModel(this.id);

  List<ItemList> itemList = [];

  //第一次的接口
  @override
  String get httpUrl =>
      UrlConfig.categoryVideoUrl + "id=$id$DETAILS_NECESSARY_PARAMETERS";

  //下拉刷新需要的接口
  @override
  String get httpLoadMoreUrl => "$loadMoreUrl$DETAILS_NECESSARY_PARAMETERS";

  @override
  void successJsonData(json) {
    var homeBodyBean = IssueList.fromJson(json);

    //保存下一个接口数据
    loadMoreUrl = homeBodyBean.nextPageUrl;

    print("分类详情数据为:$loadMoreUrl$DETAILS_NECESSARY_PARAMETERS");
    itemList.addAll(homeBodyBean.itemList);
  }

  //允许上拉加载
  @override
  bool get isLoadMore => true;
}
